<style>

</style>
<template>
  <div  style="width:100%;height:900px;background-image: url('../../static/image/beijing.jpg')" >
    <!--<img src="../../static/image/beijing.jpg"/>-->
    <div style="width: 30%;hegiht:30%;padding-top: 20%; margin: 0 auto;">
      <Form :model="user" label-position="left" :label-width="100">
        <FormItem label="用户名：">
          <Input v-model="user.username"></Input>
        </FormItem>
        <FormItem label="密码：">
          <Input type="password" v-model="user.password"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="handleSubmit('user')">登录</Button>
          <Button type="ghost" @click="handleReset('user')" style="margin-left: 8px">重置</Button>
        </FormItem>
      </Form>
    </div>
  </div>

</template>
<script>
  export default {
    data () {
      return {
        user:{
          username:'',
          password:'',
        }
      }
    },
    methods: {

        handleSubmit()
        {
          let self = this;

          this.$http.post("/api/user/login/", self.user)
            .then(response => {
              if (response.data.code == 500) {
                let responsedata=JSON.stringify(response.data.data);
                sessionStorage.setItem('user',responsedata);
                this.$router.replace({path: '/home'})
              }
              else {
                alert("账号密码错误！");

//                this.user.username='';
                this.user.password='';
                this.$router.replace({path: '/admin'})
              }
            }, response => {
              console.log("获取信息失败");
              alert("登录失败！");
            })
        }

    }


  }
</script>
